<template>
  <div class="wfull">
    <a-form :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }">
      <a-form-item label="角色名称" required>
        <ZgInput v-model="obj.name"></ZgInput>
      </a-form-item>
      <a-form-item label="角色编码" required>
        <ZgInput v-model="obj.code"></ZgInput>
      </a-form-item>
    </a-form>
  </div>
</template>
<script>
export default {
  data () {
    return {
      obj: {
        name: '',
        code: ''
      }
    }
  },
  mounted () {
    // 每次组件挂载时重置表单数据
    this.resetForm()
  },
  methods: {
    save () {
      if (this.obj.name.length === 0) {
        return this.$result.error('请输入角色名称')
      }
      if (this.obj.code.length === 0) {
        return this.$result.error('请输入角色编码')
      }
      const result = Object.assign({}, this.obj)
      // 保存成功后重置表单数据
      this.resetForm()
      return this.$result.ok(result)
    },
    resetForm () {
      this.obj = {
        name: '',
        code: ''
      }
    },
    // 公开的重置方法，供外部调用
    reset () {
      this.resetForm()
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
